package com.coco.group.controller;

import com.coco.common.annotation.IngoreResponseAdvice;
import com.coco.common.result.CommonResponse;
import com.coco.group.service.GroupBuyService;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author minicoco
 * @version 1.0
 * @date 2021/7/30 14:14
 * 用户拼团服务
 */
@RestController
@RequestMapping("/group/buy")
public class GroupBuyController {

    @Autowired(required = false)
    private GroupBuyService groupBuyService;

    /**
     * 拼团商品添加redis
     */
    @GetMapping("/addGroupGoodsToRedis")
    @IngoreResponseAdvice
    public void addGroupGoodsToRedis(){
        groupBuyService.addGroupGoodsToRedis();
    }

    /**
     * 用户发起拼团
     * @return CommonResponse
     */
    @GetMapping(value = "/startGroupBuy/{itemId}/{uid}",produces = "text/html")
    @IngoreResponseAdvice
    public String startGroupBuy(@PathVariable("itemId")Long itemId, @PathVariable("uid")Long uid){
        return groupBuyService.startGroupBuy(itemId,uid);
    }


    /**
     * 参与拼团
     * @param code 邀请码
     * @return
     */
    @GetMapping(value = "/joinGroup",produces = "text/html")
    @IngoreResponseAdvice
    public String joinGroup(@RequestParam("code") String code,@RequestParam("uid") Long uid) throws Exception {
        return groupBuyService.joinGroup(code,uid);
    }



}
